'use strict';
app.service('brandService',['$http','$q','utilService',function($http,$q,utilService){

    this.createBrand = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'brand',
            data:$scope.brand
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

//新增品牌
    this.addBrand = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'brand',
            data:$scope.brand,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
//查询ById
    this.findById = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'brand/'+ $scope.brand.id,
            params:{id:$scope.brand.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错");
        });
        return deferred.promise;
    }
//修改品牌信息
    this.editBrand = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'brand',
            data:$scope.brand,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    //删除品牌图片信息
    this.delBrandPic=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'brand/pic',
            data:$scope.brand,
            method:'DELETE'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };


//删除品牌
    this.delBrand = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'brand/del',
            data:{id:$scope.brand.id},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}]);

/*上传图片Service*/
app.service('fileUploadService',['$q','utilService',function($q,utilService){
    var _this_=this;
    _this_.del=function($scope,item){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'upload/',
            data:{filefullPath:item.fileName},
            method:'DELETE'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}])
